let express = require('express');
let bodyParser = require('body-parser');
const { response } = require('express');
let app = express()
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.use(function (request, response, next) {
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Headers", "*");
    response.setHeader("Access-Control-Allow-Methods", "*");
    next()
})

app.all('/server', (request, response) => {
    response.send('这里是服务器')
})
app.all('/delay-server', (request, response) => {
    setTimeout(() => {
        console.log('服务器返回....')
        response.send('这里是服务器')
    }, 3000)
})
app.all('*', (request, response) => {
    if (req.method.toUpperCase() === "OPTIONS") {
        res.status(200).end("ok");
        return;
    }
    res.status(404);
    res.end("not found");
})
app.listen(8090, () => {
    console.log("服务已经启动....8090");
});